// pages/assetPage/transferRecord/transferRecord.js

var wallet = require('../../wallet.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordLang:{},
    record:{},
    moneyRecord:[],
    re:{},
    clickIndex:[],
    indexFlag:true,
    id:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //console.log(options.coinType);
    this.x = 0;
    this.y = 0;
    let $this = this
    var coinType = wx.getStorageSync('coinType')
    if (options.coinType){
        coinType = JSON.parse(options.coinType)
        $this.getRecord && $this.getRecord(coinType.type, coinType.addre)
        $this.setData({
          record: coinType,
          
        })
        wx.setNavigationBarTitle({
          title: coinType.type
        })
    }else{
        $this.getRecord && $this.getRecord(coinType.type, coinType.addre)
        $this.setData({
          record: coinType
        })
        wx.setNavigationBarTitle({
          title: coinType.type
        })
    }
   
  },
  goToDetail(){
   /* wx.navigateTo({
      url: '../transferCoinDetail/transferCoinDetail',
    })*/
  },
  toAffirmMon:function(e){
    wx.navigateTo({
      url: '../affirmMoney/affirmMoney'
    })
  },
  toGetMoney(e){
   // console.log(this.data.record)
    wx.navigateTo({
      url: '../getMoneyCode/getMoneyCode' 
    })
  },
  getRecord(type,addre){
    var $this = this
    var lan = wx.T.locale == 'zh-Hans' ? 'zh_cn' :'en_us'
  //  let arr = []
    wallet.post('currency/record', { wallet_addr: addre, coin_symbol: type, language: lan  }, function (res,index) {
       console.log(res)
       let data = res.data.filter((rq,index)=>{
        // console.log(rq.tx_hash.substr(-8))
         rq.tx_hash = rq.tx_hash.substring(0, 8) + '...' + rq.tx_hash.substr(-8)
         //arr.push(index)
         return rq.tx_hash;
       })
       //console.log(data)
        $this.setData({
          moneyRecord:res.data,
         // clickIndex:arr
        })
      wx.hideNavigationBarLoading()
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      recordLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']
    })
   
  },
  confirmNum(e){
   // console.log(e)
    let flag =this.data.indexFlag
    let id = e.target.id;
    let re =this.data.re;
    let arr = []
    /*if (arr.length <= this.data.moneyRecord.length){
      //debugger
      re[id] = id
    //  console.log(re[id])
      console.log(re[id])
      arr.push(re)
      this.setData({
        clickIndex:arr
      })
      //console.log(arr)
    }*/
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  gostart(e){
    //console.log(e)
    this.x = e.changedTouches[0].clientX;

    this.y = e.changedTouches[0].clientY;
  },
  goend(e){
    let x = e.changedTouches[0].clientX;
    let y = e.changedTouches[0].clientY;
    let bottom = y - this.y
    let left = x - this.x
    if (bottom > 0 && Math.abs(left) <= 80) {
      var res = wx.getSystemInfoSync()//判断机型
      //console.log(res)
      if (/Android/i.test(res.system)) {
        //console.log('下滑')
        //console.log('333')
        //this.getCoinType && this.getCoinType()
        wx.startPullDownRefresh({
          success: function (res) {
            console.log(res)
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      }
    }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    wx.showNavigationBarLoading()
    //console.log(this.data.record)
    let type = this.data.record;
    this.getRecord && this.getRecord(type.type,type.addre)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})